﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using QLKTX1._0.DAO;
using QLKTX1._0.DTO;
namespace QLKTX1._0.GUI
{
    public partial class FrmDsPhong : Form
    {
       /* public PhongDTO phong;

        public PhongDTO Phong
        {
            get { return phong; }
            set { phong = value; }
        }*/


        public FrmDsPhong()
        {
            InitializeComponent();
           
            //this.phong = phong ;
            
        }

        
        private void FrmDsPhong_Load(object sender, EventArgs e)
        {


            cmbKhu.DataSource = KhuDAO.dsKhu();
            cmbKhu.DisplayMember = "tenKhu";
            cmbKhu.ValueMember = "maKhu";

            cmbTang.DataSource = TangDAO.dsTang();
            cmbTang.DisplayMember = "tenTang";
            cmbTang.ValueMember = "maTang";

            cmbTenPhong.DataSource = TenPhongDAO.dsTenPhong();
            cmbTenPhong.DisplayMember = "soPhong";
            cmbTenPhong.ValueMember = "maTenPhong";

            cmbSoGiuong.DataSource = SoGiuongDAO.dsSoGiuong();
            cmbSoGiuong.DisplayMember = "soLuong";
            cmbSoGiuong.ValueMember = "maSG";

            //---------------------------Dua DataTable len DataGView----------------------------------------------

            btnLuu.Enabled = false;

            dtgvDSPhong.DataSource = this.xemDsPhong();
            // thay doi ten cot
            dtgvDSPhong.Columns[0].HeaderText = "   Mã phòng    ";
            dtgvDSPhong.Columns[1].HeaderText = "   Khu nhà    ";
            dtgvDSPhong.Columns[2].HeaderText = "   Tầng    ";
            dtgvDSPhong.Columns[3].HeaderText = "   Tên phòng   ";
            dtgvDSPhong.Columns[4].HeaderText = "   Số giường   ";
            //Chinh do rong cua cot..............
            dtgvDSPhong.Columns[0].Width = 160;
            dtgvDSPhong.Columns[1].Width = 160;
            dtgvDSPhong.Columns[2].Width = 160;
            dtgvDSPhong.Columns[3].Width = 160;
            dtgvDSPhong.Columns[4].Width = 160;
            //Cam chinh sua cot, chi doc.............
            dtgvDSPhong.Columns[0].ReadOnly = true;
            dtgvDSPhong.Columns[1].ReadOnly = true;
            dtgvDSPhong.Columns[2].ReadOnly = true;
            dtgvDSPhong.Columns[3].ReadOnly = true;
            dtgvDSPhong.Columns[4].ReadOnly = true;
            //gan du lieu gridview len textbox-------------------------------
            txtMaPhong.DataBindings.Clear();
            txtMaPhong.DataBindings.Add("Text", dtgvDSPhong.DataSource, "maPhong");
            cmbKhu.DataBindings.Clear();
            cmbKhu.DataBindings.Add("Text", dtgvDSPhong.DataSource, "maKhu");
            cmbTang.DataBindings.Clear();
            cmbTang.DataBindings.Add("Text", dtgvDSPhong.DataSource, "maTang");
            cmbTenPhong.DataBindings.Clear();
            cmbTenPhong.DataBindings.Add("Text", dtgvDSPhong.DataSource, "maTenPhong");
            cmbSoGiuong.DataBindings.Clear();
            cmbSoGiuong.DataBindings.Add("Text", dtgvDSPhong.DataSource, "maSoGiuong");  

        }
        private DataTable xemDsPhong()
        {

            DataTable dt = new DataTable();

            DataColumn col1 = new DataColumn("maPhong");
            dt.Columns.Add(col1);

            DataColumn col2 = new DataColumn("maKhu");
            dt.Columns.Add(col2);

            DataColumn col3 = new DataColumn("maTang");
            dt.Columns.Add(col3);

            DataColumn col4 = new DataColumn("maTenPhong");
            dt.Columns.Add(col4);

            DataColumn col5 = new DataColumn("maSoGiuong");
            dt.Columns.Add(col5);

            foreach (PhongDTO  dot in PhongDAO .dsPhong ())
            {
                dt.AcceptChanges();

                DataRow dr = dt.NewRow(); // tao 1 hang

                dr[0] = dot.MaPhong ;
                dr[1] = dot.MaKhu .TenKhu ;
                dr[2] = dot.MaTang .TenTang ;
                dr[3] = dot.MaTenPhong.SoPhong ;
                dr[4] = dot.MaSoGiuong.SoLuong;

                dt.Rows.Add(dr);

            }
            return dt;


        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            FrmThemDsPhong frm = new FrmThemDsPhong();
          
            frm.ShowDialog();

            //this.phong = frm.PhongThem;

           // PhongDAO.themPhong(this.phong);

            //this.FrmDsPhong_Load(sender, e);
        }

        private void cmbKhuF_SelectionChangeCommitted(object sender, EventArgs e)
        {
            string maKhu = cmbKhuF.SelectedValue.ToString();

        }

        private void cmbKhuF_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
